/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source 
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.  
 */

package jdbcmanager.app;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import jdbcmanager.swing.JxDialog;
import jdbcmanager.swing.help.*;

/**
 * Creates the Application Configuration dialog box.
 * 
 * @author Francisco Morero Peyrona
 */
final class ConfigDlg extends JxDialog
{
   private JTabbedPane    tabPane  = new JTabbedPane();
   private ConfigTabGui   pnlGui   = new ConfigTabGui();
   private ConfigTabData  pnlData  = new ConfigTabData();
   private ConfigTabProxy pnlProxy = new ConfigTabProxy(); 
   
   /**
    * Application configuration dialog
    */
   ConfigDlg()
   {
      super( App.sAPP_NAME +" Configuration" );
  
      init();     
      pack();
      center();
   }

   //-------------------------------------------------------------------------//
   
   protected void onAccept( ActionEvent evt )
   {
      super.onAccept( evt );
      
      this.pnlGui.save();
      this.pnlData.save();
      this.pnlProxy.save();
   }

   protected void onHelp( ActionEvent evt )
   {
      int    nTab = this.tabPane.getSelectedIndex();
      String sTab = null;
      
      switch( nTab )
      {
         case 0 : sTab = "GUI";   break;
         case 1 : sTab = "Data";  break;
         case 2 : sTab = "Proxy"; break;
      }
      
      new JHelpDialog( this, "ConfigDialog"+ sTab );
   }

   private void init()
   {
      // Makes button Help available
      btnHelp.setVisible( true );

      // Create Tabbed pane
      this.tabPane.addTab( "User Interface", null, this.pnlGui   );
      this.tabPane.addTab( "Data Base"     , null, this.pnlData  );
      this.tabPane.addTab( "Proxy"         , null, this.pnlProxy );
      
      // Foot note -------------------------------------------
      JLabel lblNote = new JLabel( "<html><body style=\"font-family: Arial; font-size: 8px\">"+
                                   "<b>Note:</b> "+
                                   "Some of the changes will not take effect until application re-starts."+
                                   "</body></html>" );
      
      // Panel with all --------------------------------------
      JPanel pnl = new JPanel( new BorderLayout( 2,8 ) );
             pnl.add( this.tabPane, BorderLayout.CENTER );
             pnl.add( lblNote, BorderLayout.SOUTH );

      getContentPane().add( pnl, BorderLayout.CENTER );      
   }
}